package com.yiwei.hdb.api.requestInfo;

import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.api.bean.WithDrawBean;
import com.yiwei.hdb.api.callback.WithdrawApplyContract;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class WithdrawApplyRequest extends BaseRequest<WithdrawApplyContract.View> implements WithdrawApplyContract.Presenter<WithdrawApplyContract.View> {

    public static WithdrawApplyRequest create() {
        return new WithdrawApplyRequest();
    }


    @Override
    public void getWithdrawApply(String money) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        WithDrawBean bean = new WithDrawBean();
        bean.money = money;
        Api.api_service.getWithdrawApply(bean).compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();

                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getWithdrawApplySuccess(result);
                });
    }

    @Override
    public void getDealDetailInfo() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        Api.api_service.getMyFundData().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getDealDetailInfoSuccess(result);
                });
    }

    @Override
    public void getBankList() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        Api.api_service.getBankcardList().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();

                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getBankListSuccess(result);
                });
    }
}
